package wisp.gui;

import java.awt.Color;

import com.golden.gamedev.gui.TFloatPanel;
import com.golden.gamedev.gui.TLabel;
import com.golden.gamedev.gui.toolkit.UIConstants;

public class MessageWindow extends TFloatPanel {

	private boolean read;
	private int type; //0-YesNo message, 1-basic message, 2- YesNo w/ reciepient
	
	private Cbutton yesB;
	private Cbutton noB;
	
	private TLabel descriptionLabel;
	private TLabel senderLabel;
	private TLabel messageLabel;
	
	private String description;
	private String sender;
	private String message;
	
	private String acceptPrompt;
	private String denyPrompt;
	
	private Message m;
	
	public MessageWindow(String title, boolean one, boolean two, int x, int y, int w, int h){
		
		super(title, one, two, x, y, w, h);
		
    	this.setLayer(this.getLayer()+1);
    	this.setVisible(false);
    	this.setElastic(false);
    	
    	acceptPrompt = "";
    	denyPrompt = "";
    	description = "";
    	sender = "";
    	message = "";
    	
    	
    	descriptionLabel = new TLabel(description, 5, 5, 290, 100);
    	descriptionLabel.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
    	descriptionLabel.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
    	
    	senderLabel = new TLabel(sender, 5,5, 290, 20);
    	senderLabel.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
    	senderLabel.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
    	
    	messageLabel = new TLabel(message, 5, 30, 290, 100);
    	messageLabel.UIResource().put("Text Vertical Alignment Integer", UIConstants.TOP);
    	messageLabel.UIResource().put("Text Horizontal Alignment Integer", UIConstants.LEFT);
    	
    	
    	
    	yesB = new Cbutton(acceptPrompt, (this.getWidth()/2)-80-5, 110, 80, 20);
    	noB = new Cbutton(denyPrompt, (this.getWidth()/2)+5, 110, 80, 20);
    	
    	
    	yesB.setVisible(false);
    	noB.setVisible(false);
    	descriptionLabel.setVisible(false);
    	senderLabel.setVisible(false);
    	messageLabel.setVisible(false);
    	
    	this.add(senderLabel);
    	this.add(messageLabel);
    	this.add(yesB);
    	this.add(noB);
    	this.add(descriptionLabel);

	}
	
	//INITIALIZE yes/no prompt (basic)
	public void init(String desc, String a, String d){
    	type = 0;
    	acceptPrompt = a;
    	denyPrompt = d;
    	description = desc;
    	
    	yesB.setText(acceptPrompt);
    	noB.setText(denyPrompt);
    	descriptionLabel.setText(description);
    	
    	yesB.setVisible(true);
    	noB.setVisible(true);
    	descriptionLabel.setVisible(true);
    	

    	
	}
	
	//INITIALIZE basic message (w/ OK button)
	public void init(String s, String m){
		type = 1;
		
		sender = s;
		message = m;
		
		senderLabel.setText(sender);
		messageLabel.setText(message);
		
		senderLabel.setVisible(true);
		messageLabel.setVisible(true);
	}

	//INITIALIZE yes/no prompt (w/reciever)
	public void init(Message m, String a, String d){
    	type = 2;
    	acceptPrompt = a;
    	denyPrompt = d;
    	description = m.messagebody;
    	sender = m.sender;
    	
    	
    	yesB.setText(acceptPrompt);
    	noB.setText(denyPrompt);
    	descriptionLabel.setText(description);
    	
    	yesB.setVisible(true);
    	noB.setVisible(true);
    	descriptionLabel.setVisible(true);
    	

    	
	}
	
	public void clearThis(){
    	acceptPrompt = "";
    	denyPrompt = "";
    	description = "";
    	sender = "";
    	message = "";
	}
	public int getType(){
		return type;
	}
	public boolean read(){
		return read;
	}
	
	public boolean yesClicked(){
		boolean temp = false;
		
		if(yesB.clicked()){
			temp = true;
			yesB.clearClick();
		}else{
			temp = false;
		}
		return temp;
	}
	
	public boolean noClicked(){
		boolean temp = false;
		
		if(noB.clicked()){
			temp = true;
			noB.clearClick();
		}else{
			temp = false;
		}
		return temp;
	}

	public String getAcceptPrompt() {
		return acceptPrompt;
	}

	public String getDenyPrompt() {
		return denyPrompt;
	}

	public String getDescription() {
		return description;
	}

	public String getMessage() {
		return message;
	}

	public boolean isRead() {
		return read;
	}

	public String getSender() {
		return sender;
	}
	
	public Message getMessageObj(){
		return m;
	}
	
	public void setMessageObj(Message m1){
		m = m1;
	}
}
